package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

public class Discount extends JFrame {

	private JPanel contentPane;
	private JTextField txtName;
	private JTextField txtDiscount;
	private Success suc;

	/**
	 * Create the frame.
	 */
	public Discount(String s) {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 220, 130);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnSave = new JButton("Save");
		if(s.equals("new"))
		{
			setTitle("Add discount");
			btnSave.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					suc=new Success("cr", false);
					suc.setVisible(true);
					dispose();
				}
			});
			btnSave.setBounds(109, 61, 89, 23);
			contentPane.add(btnSave);
		}
		else
		{
			setTitle("Manage discount");
			btnSave.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					suc=new Success("mng", false);
					suc.setVisible(true);
					dispose();
				}
			});
			btnSave.setBounds(109, 61, 89, 23);
			contentPane.add(btnSave);
		}
		
		JLabel lblName = new JLabel("Name:");
		lblName.setBounds(10, 11, 66, 14);
		contentPane.add(lblName);
		
		JLabel lblDiscount = new JLabel("Discount:");
		lblDiscount.setBounds(10, 36, 66, 14);
		contentPane.add(lblDiscount);
		
		txtName = new JTextField();
		txtName.setBounds(86, 8, 100, 17);
		contentPane.add(txtName);
		txtName.setColumns(10);
		
		txtDiscount = new JTextField();
		txtDiscount.setBounds(86, 33, 75, 17);
		contentPane.add(txtDiscount);
		txtDiscount.setColumns(10);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				MainMenu.getInstance().setVisible(true);
				dispose();
			}
		});
		btnCancel.setBounds(10, 61, 89, 23);
		contentPane.add(btnCancel);
		
		JLabel label = new JLabel("%");
		label.setBounds(171, 36, 15, 14);
		contentPane.add(label);
		
	}

}
